/**
 * 这是用户名片的分享图
 */
const app = getApp()
const imgUrl = app.globalData.imgUrl
let uploadsUrl = app.globalData.uploadsUrl
const rate = 1.0
let offsetLeft = 0*rate;
let offsetTop = 0*rate;
export default class LastMayday {
  palette(qrCodeUrl, data, isShare) { 
    uploadsUrl = app.globalData.uploadsUrl
    if(isShare) offsetTop = -530*rate;
    else offsetTop = 0;
    return ({
      width: 750 * rate +'px',
      height: 1350 * rate +'px',
      background: '#ffffff',
      views: [  
        //商品图片
        {
          type: 'image',
          url: uploadsUrl+data.coverImg,
          css: {
            top: offsetTop + 0 * rate + 'px',
            left: offsetLeft + 0 * rate + 'px',
            width: 750 * rate +'px',
            height: 750 * rate +'px',
          },
        },


        {
          type: 'text',
          text: wx.getStorageSync('userInfo').nikename || wx.getStorageSync('userInfo').realName || '',
          css: {
            top: offsetTop +840 * rate + `px`,
            left: offsetLeft + 20 * rate + "px",
            fontSize: 44 * rate + 'px',
            color: '#333',
            width: 700 * rate + 'px',
            lineHeight: 50 * rate + 'px',
            maxLines: 1,
            // fontWeight: 'bold'
          }
        },

        {
          type: 'text',
          text: '邀请你一起买',
          css: {
            top: offsetTop + 910 * rate + `px`,
            left: offsetLeft + 20 * rate + "px",
            fontSize: 44 * rate + 'px',
            color: '#333',
            width: 700 * rate + 'px',
            lineHeight: 50 * rate + 'px',
            maxLines: 1,
            // fontWeight: 'bold'
          }
        },

        
        // //标题
        {
          type: 'text',
          text: data.goodsName,
          css: { 
            top: offsetTop + 990 * rate +`px`,
            left: offsetLeft + 20 * rate +"px",
            fontSize: 28 * rate +'px',
            color: '#666',
            width: 350 * rate + 'px',
            lineHeight: 50 * rate + 'px',        
            maxLines: 2,
            // fontWeight: 'bold'
          }
        },

        // //价格
        {
          type: 'text',
          text: '¥'+data.price,
          css: {
            fontSize:  60 * rate +'px',
            top: offsetTop + 1180 * rate +`px`,
            left: offsetLeft + 20 * rate +"px",
            color: '#ff0000',
            // fontWeight:'bold'
          }
        },
 

        // //灰色细线 
        // {
        //   type: 'rect',
        //   css: {
        //     left: offsetLeft + 20 * rate +'px',
        //     top: offsetTop + 780 * rate +'px',
        //     color: '#ccc',
        //     width: 710 * rate +'px',
        //     height: 2 * rate +'px',
        //   },
        // },
 

        // //小程序码
        {
          type: 'image',
          url: qrCodeUrl,
          css: {
            top: offsetTop + 830 * rate +`px`,
            left: offsetLeft + 430 * rate +`px`,
            width: 280 * rate +'px',
            height:280 * rate +'px',
          },
        },
        {
          type: 'text',
          text: '扫码或长按识别二维码',
          css: {
            top: offsetTop + 1130 * rate +`px`,
            left: offsetLeft + 445 * rate +"px",
            fontSize: 28 * rate +'px',
            color: '#A6A6A6',
          },
        },
      ],
    });
  }
}


//计算出阴影的宽度
function calc_shadow_width(text) {
  return text.length*56+48;
}

function getShadow(text, row, left_text) {
  left_text = left_text || ""
  var left_width = left_text ? calc_shadow_width(left_text)+24:0
  return {
    type: 'rect',
    css: {
      top: `${444+(row-1)*128}px`,
      left: `${48 + left_width}px`,
      color: '#FFC5C5',
      borderRadius: '32px',
      width: `${calc_shadow_width(text)}px`,
      height: '96px',
    },
  }
}

function getText(text, row, left_text) {
  left_text = left_text || ""
  var left_width = left_text ? calc_shadow_width(left_text) + 24 : 0
  return {
    type: 'text',
    text: text,
    css: {
      top: `${462 + (row - 1) * 128}px`,
      left: `${72 + left_width}px`,
      fontSize: '56px',
      fontWeight: 'normal',
      color: '#333',      
    },
  }
}